import { useRef, useState, useEffect } from 'react'

export default function useDebounce(fn: () => void, delay = 500) {
  //用来存储计时器
  let timer: any = null

  return () => {
    if (timer) {
      clearTimeout(timer) // 每次点击，重新开始计时
    }
    timer = setTimeout(fn, delay)
  }
}
